import { action } from 'mobx';

import Constants from '../constants/constants';
import Base from './base';

class User extends Base {

  @action
  async load() {

    // 请求列表
    const url = Constants.URL + '/user';
    const option = { method: 'GET' };
    await super.load(url, option);
  }

  @action
  async remove(id) {

    // 请求删除
    const url = Constants.URL + '/user/' + id;
    const option = { method: 'DELETE' };
    await super.remove(url, option);

    // 如果删除成功，重新取得列表
    if (this.response.remove == Constants.Code.SUCCESS) {
      this.load();
    }
  }
}

export default new User();